<!--
 * @Description: pdf预览页面
 * @Author: ZhangHan
 * @Date: 2025-08-07 16:56:20
 * @LastEditTime: 2025-08-08 10:17:37
 * @LastEditors: ZhangHan
-->
<template>
  <view>
    <!-- #ifdef H5 -->
    <!-- <vue-pdf-embed v-if="pdfViewerUrl" :source="pdfViewerUrl" style="width: 100%; height: 100vh" /> -->
    <h5-pdf-viewer v-if="pdfViewerUrl" :url="pdfViewerUrl" />
    <view v-else>加载中</view>
    <!-- #endif -->
  </view>
</template>

<script setup lang="ts">
import { onLoad } from "@dcloudio/uni-app";
import { ref, defineAsyncComponent } from "vue";

// import VuePdfEmbed from "vue-pdf-embed";

const pdfViewerUrl = ref<any>("");

// H5 专用组件（完全隔离）
// #ifdef H5
const H5PdfViewer = defineAsyncComponent(() =>
  import("vue-pdf-embed").then((module) => ({
    template: `
      <vue-pdf-embed 
        :source="url" 
        style="width: 100%; height: 100vh" 
      />`,
    components: { VuePdfEmbed: module.default },
    props: ["url"],
  }))
);
// #endif

onLoad((options) => {
  // 确保隐藏分享按钮
  // #ifdef MP-WEIXIN
  uni.hideShareMenu({ hideShareItems: ["qq"] });
  // #endif
  console.log("🚀 ~ options:", options);
  pdfViewerUrl.value = JSON.parse(options?.data);

  console.log(pdfViewerUrl.value);
});
</script>
